package top.ivansong92.example.leetcode.learning.other.string;

import org.junit.Test;

import java.util.Arrays;
import java.util.List;

public class TestJob {
    public boolean wordBreak(String s, List<String> wordDict) {
        if ((wordDict == null || wordDict.size() == 0) && (s == null || s.length() == 0)) {
            return true;
        }

        if (wordDict == null || wordDict.size() == 0 || s == null || s.length() == 0) {
            return false;
        }

        boolean[] res = new boolean[s.length() + 1];
        res[0] = true;
        for(int i = 1; i <= s.length(); i ++) {
            for(int j = 0; j < i; j ++) {
                if (res[j] && wordDict.contains(s.substring(j, i))) {
                    res[i] = true;
                    break;
                }
            }
        }
        return res[s.length()];
    }


    @Test
    public void test1() {
        System.out.println(wordBreak("cars", Arrays.asList("car", "ca", "rs", "dd")));
    }
}
